package com.hxzy.core.tags.el;

/**
 * <p>
 * 类描述：输出日期格式化
 * <p>
 * 创建人：Abdi
 * <p>
 * 创建时间：2013-11-6 下午08:46:53
 */
public class ElDateFormat {
	public static String format(String date,String pattern){
		if(null == date || null == pattern){
			return date;
		}
		if("yyyy-MM-dd".equals(pattern) && date.length() >= 8){
			return date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8);
		}else if("yyyy/MM/dd".equals(pattern) && date.length() >= 8){
			return date.substring(0, 4) + "/" + date.substring(4, 6) + "/" + date.substring(6, 8);
		}else if("yyyy年MM月dd日".equals(pattern) && date.length() >= 8){
			return date.substring(0, 4) + "年" + date.substring(4, 6) + "月" + date.substring(6, 8) + "日";
		}else if("yyyy-MM-dd hh:mm:ss".equals(pattern) && date.length() >= 14){
			return date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8)
				+ " " + date.substring(8, 10) + ":" + date.substring(10, 12) + ":" + date.substring(12, 14);
		}else if("yyyy年MM月dd日 hh时mm分ss秒".equals(pattern) && date.length() >= 14){
			return date.substring(0, 4) + "年" + date.substring(4, 6) + "月" + date.substring(6, 8) + "日"
			+ " " + date.substring(8, 10) + "时" + date.substring(10, 12) + "分" + date.substring(12, 14) + "秒";
		}
		return date;
	}
	
	public static void main(String[] args) {
		System.out.println(format("20131106121020", "yyyy-MM-dd hh:mm:ss"));
	}
}